home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / cvs / sprite / main.c < prev    next >
C/C++ Source or Header  |  1991-09-10  |  7KB  |  240 lines

  1. char rcsid[] = "$Id: main.c,v 1.2 91/09/10 16:12:21 jhh Exp $\nPatch level ###\n";
  2.  
  3. /*
  4.  *    Copyright (c) 1989, Brian Berliner
  5.  *
  6.  *    You may distribute under the terms of the GNU General Public License
  7.  *    as specified in the README file that comes with the CVS 1.0 kit.
  8.  *
  9.  * This is the main C driver for the CVS system.
  10.  *
  11.  * Credit to Dick Grune, Vrije Universiteit, Amsterdam, for writing
  12.  * the shell-script CVS system that this is based on.
  13.  *
  14.  * Usage:
  15.  *    cvs [options] command [options] [files/modules...]
  16.  *
  17.  * Where "command" is composed of:
  18.  *        checkout    Check out a module/dir/file
  19.  *        update        Brings work tree in sync with repository
  20.  *        commit        Checks files into the repository
  21.  *        diff        Runs diffs between revisions
  22.  *        log        Prints to "rlog" information for files
  23.  *        add        Adds an entry to the repository
  24.  *        remove        Removes an entry from the repository
  25.  *        status        Status info on the revisions
  26.  *        join        Merge two RCS revisions
  27.  *        patch        "patch" format diff listing between releases
  28.  *        tag        Add/delete a symbolic tag to the RCS file
  29.  *
  30.  * Future:
  31.  *        checkin        Adds new *directories* to the repository
  32.  *                Currently being done by an external shell
  33.  *                script.
  34.  *
  35.  * Brian Berliner
  36.  * 4/20/89
  37.  */
  38.  
  39. #include <sys/param.h>
  40. #include "cvs.h"
  41. #include "patchlevel.h"
  42.  
  43. char *progname, *command;
  44.  
  45. char *fileargv[MAXFILEPERDIR];
  46. int fileargc;
  47.  
  48. int use_editor = TRUE;
  49. int cvswrite = !CVSREAD_DFLT;
  50. int really_quiet = FALSE;
  51. int quiet = FALSE;
  52. int force_tag_match = FALSE;
  53.  
  54. /*
  55.  * Globals for the lists created in Collect_Sets()
  56.  */
  57. char Clist[MAXLISTLEN], Glist[MAXLISTLEN], Mlist[MAXLISTLEN];
  58. char Olist[MAXLISTLEN], Alist[MAXLISTLEN], Rlist[MAXLISTLEN];
  59. char Wlist[MAXLISTLEN], Llist[MAXLISTLEN], Blist[MAXLISTLEN];
  60. char Dlist[MAXLISTLEN];
  61.  
  62. /*
  63.  * Globals which refer to a particular file
  64.  */
  65. char Repository[MAXPATHLEN];
  66. char User[MAXPATHLEN], Rcs[MAXPATHLEN];
  67. char VN_User[MAXPATHLEN], TS_User[MAXPATHLEN];
  68. char VN_Rcs[MAXPATHLEN], TS_Rcs[MAXPATHLEN];
  69. char Tag[MAXPATHLEN], Date[MAXPATHLEN];
  70.  
  71. /*
  72.  * Options is used to hold options passed on to system(), while prog
  73.  * is alwys used in the calls to system().
  74.  */
  75. char Options[MAXPATHLEN];
  76. char prog[MAXPROGLEN];
  77.  
  78. /*
  79.  * Defaults, for the environment variables that are not set
  80.  */
  81. char *Rcsbin = RCSBIN_DFLT;
  82. char *Editor = EDITOR_DFLT;
  83. char *CVSroot = CVSROOT_DFLT;
  84.  
  85. main(argc, argv)
  86.     int argc;
  87.     char *argv[];
  88. {
  89.     extern char *getenv();
  90.     register char *cp;
  91.     register int c;
  92.     int help = FALSE, err = 0;
  93.  
  94.     /*
  95.      * Just save the last component of the path for error messages
  96.      */
  97.     if ((progname = rindex(argv[0], '/')) == NULL)
  98.     progname = argv[0];
  99.     else
  100.     progname++;
  101.  
  102.     /*
  103.      * Query the environment variables up-front, so that
  104.      * they can be overridden by command line arguments
  105.      */
  106.     if ((cp = getenv(RCSBIN_ENV)) != NULL)
  107.     Rcsbin = cp;
  108.     if ((cp = getenv(EDITOR_ENV)) != NULL)
  109.     Editor = cp;
  110.     if ((cp = getenv(CVSROOT_ENV)) != NULL)
  111.     CVSroot = cp;
  112.     if (getenv(CVSREAD_ENV) != NULL)
  113.     cvswrite = FALSE;
  114.  
  115.     optind = 1;
  116.     while ((c = getopt(argc, argv, "rwvb:e:d:H")) != -1) {
  117.     switch (c) {
  118.     case 'r':
  119.         cvswrite = FALSE;
  120.         break;
  121.     case 'w':
  122.         cvswrite = TRUE;
  123.         break;
  124.     case 'v':
  125.         (void) sprintf(index(rcsid, '#'), "%d\n", PATCHLEVEL);
  126.         (void) fputs(rcsid, stdout);
  127.         (void) fputs("\nCopyright (c) 1989, Brian Berliner\n\n\
  128. CVS may be copied only under the terms of the GNU General Public License,\n\
  129. a copy of which can be found with the CVS 1.0 distribution kit.\n", stdout);
  130.         exit(0);
  131.         break;
  132.     case 'b':
  133.         Rcsbin = optarg;
  134.         break;
  135.     case 'e':
  136.         Editor = optarg;
  137.         break;
  138.     case 'd':
  139.         CVSroot = optarg;
  140.         break;
  141.     case 'H':
  142.         help = TRUE;
  143.         break;
  144.     case '?':
  145.     default:
  146.         usage();
  147.     }
  148.     }
  149.     argc -= optind;
  150.     argv += optind;
  151.     if (argc < 1)
  152.     usage();
  153.  
  154.     /*
  155.      * Specifying just the '-H' flag to the sub-command causes a Usage
  156.      * message to be displayed.
  157.      */
  158.     command = cp = argv[0];
  159.     if (help == TRUE || (argc > 1 && strcmp(argv[1], "-H") == 0))
  160.     argc = -1;
  161.  
  162.     /*
  163.      * Make standard output line buffered, so that progress can be
  164.      * monitored when redirected to a file, but only when we're not
  165.      * running the "patch" command, as it generates lots of output
  166.      * to stdout -- just leave it block buffered.
  167.      */
  168.     if (strcmp(cp, "patch") != 0)
  169.     setlinebuf(stdout);
  170.  
  171.     if (strcmp(cp, "update") == 0)
  172.     err += update(argc, argv);
  173.     else if (strcmp(cp, "commit") == 0 || strcmp(cp, "ci") == 0)
  174.     commit(argc, argv);
  175.     else if (strcmp(cp, "diff") == 0)
  176.     diff(argc, argv);
  177.     else if (strcmp(cp, "checkout") == 0 || strcmp(cp, "co") == 0 ||
  178.         strcmp(cp, "get") == 0)
  179.     checkout(argc, argv);
  180.     else if (strcmp(cp, "log") == 0)
  181.     log(argc, argv);
  182.     else if (strcmp(cp, "status") == 0)
  183.     status(argc, argv);
  184.     else if (strcmp(cp, "add") == 0)
  185.     add(argc, argv);
  186.     else if (strcmp(cp, "remove") == 0)
  187.     remove(argc, argv);
  188.     else if (strcmp(cp, "join") == 0)
  189.     join(argc, argv);
  190.     else if (strcmp(cp, "patch") == 0)
  191.     patch(argc, argv);
  192.     else if (strcmp(cp, "tag") == 0)
  193.     tag(argc, argv);
  194.     else if (strcmp(cp, "info") == 0)
  195.     info(argc, argv);
  196.    else
  197.     usage();            /* oops.. no match */
  198.     Lock_Cleanup(0);
  199.     exit(err);
  200. }
  201.  
  202. static
  203. usage()
  204. {
  205.     (void) fprintf(stderr,
  206.     "Usage: %s [cvs-options] command [command-options] [files...]\n",
  207.            progname);
  208.     (void) fprintf(stderr, "\tWhere 'cvs-options' are:\n");
  209.     (void) fprintf(stderr, "\t\t-r\t\tMake checked-out files read-only\n");
  210.     (void) fprintf(stderr,
  211.     "\t\t-w\t\tMake checked-out files read-write (default)\n");
  212.     (void) fprintf(stderr, "\t\t-v\t\tCVS version and copyright\n");
  213.     (void) fprintf(stderr, "\t\t-b bindir\tFind RCS programs in 'bindir'\n");
  214.     (void) fprintf(stderr,
  215.     "\t\t-e editor\tUse 'editor' for editing log information\n");
  216.     (void) fprintf(stderr, "\t\t-d CVS_root_directory\n");
  217.     (void) fprintf(stderr, "\t\t\t\t\Points to the root of the CVS tree\n");
  218.     (void) fprintf(stderr, "\tand 'command' is:\n");
  219.     (void) fprintf(stderr, "\t\tcheckout\tCreates a new CVS directory\n");
  220.     (void) fprintf(stderr,
  221.     "\t\tupdate\t\tBrings work tree in sync with repository\n");
  222.     (void) fprintf(stderr,
  223.     "\t\tcommit\t\tChecks files into the repository\n");
  224.     (void) fprintf(stderr, "\t\tdiff\t\tRuns diffs between revisions\n");
  225.     (void) fprintf(stderr,
  226.     "\t\tlog\t\tPrints out 'rlog' information for files\n");
  227.     (void) fprintf(stderr, "\t\tstatus\t\tStatus info on the revisions\n");
  228.     (void) fprintf(stderr, "\t\tadd\t\tAdds an entry to the repository\n");
  229.     (void) fprintf(stderr,
  230.     "\t\tremove\t\tRemoves an entry from the repository\n");
  231.     (void) fprintf(stderr,
  232.     "\t\tjoin\t\tJoins an RCS revision with the head on checkout\n");
  233.     (void) fprintf(stderr,
  234.     "\t\tpatch\t\t\"patch\" format diffs between releases\n");
  235.     (void) fprintf(stderr, "\t\ttag\t\tAdd a symbolic tag to the RCS file\n");
  236.     (void) fprintf(stderr,
  237.     "\tSpecify the '-H' option to each command for Usage information\n");
  238.     exit(1);
  239. }
  240.